//
//  SearchManager.m
//  EasyToo
//
//  Created by zhengzhe on 13-10-13.
//
//

#import "SearchManager.h"
#import "ServerCommunicationManager.h"
#import "SearchGoodsRequest.h"
#import "SearchGoodsResponse.h"
#import "SearchCouponRequest.h"
#import "SearchCouponResponse.h"


@implementation SearchManager
static SearchManager* gManager = nil;

+ (SearchManager*)shareManager
{
    if (gManager == nil) {
        gManager = [[SearchManager alloc] init];
    }
    return gManager;
}

- (void)searchGoods:(NSString *)keyword
{
    SearchGoodsRequest *request = [[SearchGoodsRequest alloc] initWithKeyWord:keyword PageIndex:1 PageNum:20 Delegate:self];
    [[ServerCommunicationManager GetServerCommunication] sendRequest:request];
    [request release];
}

- (void)searchCoupon:(NSString *)keyword
{
    SearchCouponRequest *request = [[SearchCouponRequest alloc] initWithKeyWord:keyword PageIndex:1 PageNum:20 Delegate:self];
    [[ServerCommunicationManager GetServerCommunication] sendRequest:request];
    [request release];
}

- (void)onRequestSuccess:(BaseResponse *)response
{
    if ([response isKindOfClass:[SearchGoodsResponse class]])
    {
        NSMutableArray *goodsArray = ((SearchGoodsResponse*)response).goodsArray;
        if (goodsArray && [goodsArray count] > 0) {
            [self.delegate onSearchGoodsFinish:YES GoodsArray:goodsArray];
        }
        else
        {
            [self.delegate onSearchGoodsFinish:NO GoodsArray:nil];
        }
    }

}

- (void)onRequestFail:(BaseResponse *)response
{
    if ([response isKindOfClass:[SearchGoodsResponse class]])
    {
        [self.delegate onSearchGoodsFinish:NO GoodsArray:nil];
    }
}




@end
